/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DBL;

import MDL.*;
import java.sql.*;

/**
 *
 * @author Niklas
 */
public class DBFaktura implements IFDBFaktura
{
    Connection con = DBConnection.getInstance().getDBcon();

    public DBFaktura()
    {

    }

    public int createFaktura(Faktura faktura)
    {
        int fakturaId = GetMax.getNextID("SELECT MAX (fakturaId) FROM FAKTURA");
        fakturaId++;

        int rc = -1;
        String query = "INSERT INTO FAKTURA (fakturaId, betalingsdato, antal, fakturaNr) VALUES("+fakturaId+",'"+faktura.getBetalingsdato()+"',"+faktura.getAntal()+","+faktura.getFakturaNr()+")";

        System.out.println(query);
        try
        {
            Statement state = con.createStatement();
            state.setQueryTimeout(6);
            rc = state.executeUpdate(query);
            state.close();
        } catch (Exception e)
        {
            System.out.println("ERROR:" + e);
        }
        System.out.println(rc);
        return rc;
    }


}
